package com.ruyuan.eshop.common.enums;

import com.google.common.collect.Maps;

import java.util.Map;

/**
 * 价格分类枚举
 *
 * @author zhonghuashishan
 * @version 1.0
 */
public enum PriceTypeEnum {

    /**
     * 商城价
     */
    BASE_PRICE(1, "商城价"),
    /**
     * 会员价
     */
    VIP_PRICE(2, "会员价");

    private Integer code;

    private String value;

    PriceTypeEnum(Integer code, String value) {
        this.code = code;
        this.value = value;
    }

    public Integer getCode() {
        return code;
    }

    public String getValue() {
        return value;
    }

    public static Map<Integer, String> toMap(){
        Map<Integer, String> map = Maps.newHashMap();
        for (PriceTypeEnum element : PriceTypeEnum.values() ){
            map.put(element.getCode(),element.getValue());
        }
        return map;
    }

    public static PriceTypeEnum getByCode(Integer code){
        if(code == null) {
            return null;
        }
        for(PriceTypeEnum element : PriceTypeEnum.values()){
            if (code.equals(element.getCode())) {
                return element;
            }
        }
        return null;
    }

}